home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / Tele / D-F / Death to NCSA! ƒ / NCSA.c < prev   
Encoding:
C/C++ Source or Header  |  1993-02-18  |  4.3 KB  |  181 lines  |  [TEXT/KAHL]

  1. /***********
  2.     NCSA.c
  3.     A program to automatically kill NCSA Telnet settings files.
  4.     By Wade Williams
  5.     williw1@mail.auburn.edu
  6.     WadesWorld@aol.com
  7.     
  8.     Wade Williams holds copyright (1993) to this source code.
  9.     You are free to distribute this utility. 
  10.     
  11.     Note to users:  You probably have no need whatsoever for this application.
  12.     
  13.     Why use this program?  If you're a network administrator who sets up NCSA Telnet, 
  14.     you probably spend a lot of time deleting the NCSA Telnet Settings file from the System
  15.     Folder.  Rather than having to delete it each time by opening the system folder and
  16.     dragging it to the trash, I wrote this quick hack which deletes the file.
  17.     
  18.     Note to beginning programmers:  This is not terribly good style to learn from.  I wrote
  19.     this quickly, and for a very specific purpose.  As a Macintosh application, it really
  20.     violates a ton of guidelines.  There is no interface, the error handling is minimal,
  21.     there is no event handling, it can't background, etc.  Again, this application has
  22.     one purpose and one purpose only - to *quickly* delete the file.
  23.     
  24. *********************/
  25.  
  26. /***************** Function Prototypes ******************/
  27. void InitToolBox(void);
  28. void GetEnv(void);
  29. void ShowMyDLOG(void);
  30. void DeleteFile(void);
  31.  
  32. /***************** GLOBAL VARIABLES ******************/
  33.  
  34.     OSErr        errCode;  /*  For return variables */
  35.     short        item;
  36.     SysEnvRec    theSysEnv;
  37.     Str255        errString;
  38.     
  39.     #define SYSENVERR    128        /* ID's of our various dialogs and alerts, except delay */
  40.     #define STATDLOG    128
  41.     #define DELAY        1000000
  42.     #define NODLOG        131
  43.     #define    NOFILE        130
  44.     #define FILEERR        129
  45.  
  46.  
  47.  
  48. /***************** INIT TOOLBOX ******************/
  49.  
  50. void InitToolBox(void)
  51. {
  52.     /*  Init the entire toolbox and in the proper sequence! */
  53.     
  54.     InitGraf (&thePort);
  55.     InitFonts();
  56.     InitWindows();
  57.     InitMenus();
  58.     TEInit();
  59.     InitDialogs(0L);
  60.     InitCursor();
  61.     MaxApplZone();
  62.     FlushEvents(everyEvent,0);
  63. }
  64.  
  65. /***************** GET ENV ******************/
  66.  
  67. void GetEnv(void)
  68. {
  69.     /***    
  70.     Make a call to SysEnvirons to find out the ID of the
  71.     "blessed" folder (the system folder).  We use SysEnvirons
  72.     instead of Gestalt to maintain System 6 compatibility
  73.     ***/
  74.         
  75.     errCode = SysEnvirons(1, &theSysEnv);
  76.     
  77.     if (errCode) /* if there was an error... (not zero) */
  78.     {
  79.                 /* convert the error code to a string */
  80.             NumToString(errCode, errString);
  81.                 /* Put it in the Alert */
  82.             ParamText(errString, nil, nil, nil);
  83.                 /* Display the error alert */
  84.             item=StopAlert(SYSENVERR, nil);
  85.                 /*  Abort */
  86.             ExitToShell();
  87.     }
  88. }
  89.  
  90. /***************** SHOW MY DLOG ******************/
  91.  
  92. void ShowMyDLOG(void)
  93. {
  94.     DialogPtr    theDialog;
  95.     long        i;
  96.     GrafPtr        savePort;
  97.     
  98.         /*  Be a friendly program, save the port */
  99.     GetPort(&savePort);
  100.  
  101.         /* Get the Deleting Dialog */
  102.     theDialog = GetNewDialog(STATDLOG, nil, (DialogPtr) -1);
  103.         /* if there was not an error (returned a valid ptr) */
  104.     if (theDialog)
  105.     {
  106.             /* Set the port to our dialog */
  107.         SetPort(theDialog);
  108.             /*    
  109.             Draw the dialog - necessary because modaldialog() is
  110.             never called
  111.             */
  112.         UpdtDialog(theDialog, theDialog->visRgn);
  113.             /*  Delay for a short time so we can see the dialog */
  114.         for (i=0;i<DELAY;i++)
  115.         ;
  116.             /*  Get rid of the dialog */
  117.         DisposeDialog(theDialog);
  118.     }
  119.     else
  120.     {
  121.             /* Display the error alert */
  122.         item=StopAlert(NODLOG,nil);
  123.             /*  Abort */
  124.         ExitToShell();
  125.     }
  126.     
  127.         /* Like a good program, we reset the port */
  128.     SetPort(savePort);
  129. }
  130.  
  131. /***************** DELETE FILE ******************/
  132.  
  133. void DeleteFile(void)
  134. {
  135.         /*
  136.         Delete the file, using the ID of the system folder returned by
  137.         SysEnvirons
  138.         */
  139.         
  140.     errCode = FSDelete("\pNCSA Telnet Settings", theSysEnv.sysVRefNum);
  141.     
  142.     /*  If there was an error (ie not 0) */
  143.     if (errCode)
  144.     {
  145.             /* if it was file not found */
  146.         if (errCode == -43)
  147.         {
  148.                 /* convert the error code to a string */
  149.             NumToString(errCode, errString);
  150.                 /*  Put it in the alert */
  151.             ParamText(errString, nil, nil, nil);
  152.                 /*  display the alert */
  153.             item=CautionAlert(NOFILE,nil);
  154.                 /* Abort */
  155.             ExitToShell();
  156.         }
  157.         else /*  if it was some other file system error... */
  158.         {
  159.                 /* convert the error code to a string */
  160.             NumToString(errCode, errString);
  161.                 /*  Put it in the alert */
  162.             ParamText(errString, nil, nil, nil);
  163.                 /*  display the alert */
  164.             item=StopAlert(FILEERR,nil);
  165.                 /* Abort */
  166.             ExitToShell();
  167.         }
  168.     }
  169. }
  170.  
  171. /***************** MAIN ******************/
  172.  
  173. main()
  174. {
  175.     InitToolBox();
  176.     GetEnv();
  177.     ShowMyDLOG();
  178.     DeleteFile();
  179.  
  180.  
  181. }